#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <QFileInfo>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    dirPath = QFileDialog::getExistingDirectory(this, "获取文件目录", "C:/Users/NAIM/Desktop/");
    QStringList list = QDir(dirPath).entryList();
    for (auto a : list)
    {
        if (a == "." || a == "..")
            continue;
        ui->listWidget->addItem(a);
    }
}

void MainWindow::on_listWidget_itemDoubleClicked(QListWidgetItem *item)
{
    QFileInfo info(dirPath + "/" + item->text());
    qDebug() << dirPath + item->text();
    if (info.isDir())
        ui->textBrowser->setText("它是一个目录");
    if (info.isFile())
        ui->textBrowser->setText("它是一个文件\n文件大小: " + QString::number(info.size()) + "\n文件后缀名:" + info.suffix());
}
